import {AbilityModel} from "../../controller/model/AbilityModel";
import Configer from "../../frame/apiModel/config/Configer";
import {FinalKey} from "../../constant/FinalConstant";
import {UnitController} from "../../controller/UnitController";
import {Logger} from "../../frame/apiModel/config/Logger";
import {UnitModel} from "../../frame/apiModel/adapterModel/model3/UnitModel";
import {ItemModel} from "../../frame/apiModel/adapterModel/model3/ItemModel";
import {PlayerModel} from "../../frame/apiModel/adapterModel/model4/PlayerModel";
import {LocModel} from "../../frame/apiModel/base/LocModel";
import {PlayerFactory} from "../../frame/PlayerFactory";
import {DataRouterUtil} from "../../utils/router/DataRouterUtil";
import {CodeUtil} from "../../frame/codeAdapter/CodeUtil";
import {AttributeEnum} from "../../frame/dataSource/DataModel";
import {Util} from "../../utils/Util";
import {AbilityUtil} from "./AbilityUtil";
import UnitUtil from "../../utils/UnitUtil";
import {DataRouter} from "../../frame/dataSource/DataRouter";

export default class ShowFightValueSkillModel extends AbilityModel {
    abilityId: string = Configer.getFinal(FinalKey.showFightValue) as string;

    actionFun = (activeUnit: UnitModel, activeItem: ItemModel, targetUnit: UnitModel, targetItem: ItemModel, activePlayer: PlayerModel, targetPlayer: PlayerModel, spellId: string, spellLoc: LocModel)  => {
        let success;
        this.showFightValue(activePlayer, targetUnit, targetItem);
        return success;
    }

    showFightValue(player: PlayerModel, targetUnit: UnitModel, targetItem: ItemModel) {
        if (targetUnit) {
            const ret = UnitUtil.getAttribute(targetUnit);
            const unitAttr = ret.newestAttribute;
            const fightValue = UnitUtil.getFightValueByAttr(unitAttr);
            Logger.toastProduct(`单位 ${targetUnit.name} 战斗力为: ${fightValue}`, player)
        } else if (targetItem) {
            const itemId = targetItem.strId;
            const itemData = DataRouter.getItemDataByItemId(itemId);
            const attrId = itemData.attrId;
            const itemAttr = DataRouterUtil.getAttrByAttrInterface(attrId, 1);
            const fightValue = UnitUtil.getFightValueByAttr(itemAttr.unitAttr);
            Logger.toastProduct(`物品 ${targetItem.name} 战斗力为: ${fightValue}`, player)
        }
    }
}